package createThread.cn.tedu.threaddemo.test3;

import java.util.Scanner;
import java.util.concurrent.atomic.AtomicBoolean;


public class threadBreak {
    static boolean isRunning = false;
    public static void main(String[] args) {

        Thread t = new Thread(()->{
            Thread cur = Thread.currentThread();
            while(!cur.isInterrupted()){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
                    e.printStackTrace();
                    break;
                }
                System.out.println("thread-1");
            }
        });
        t.start();
        /**
         * 在一个线程中如果run方法执行完了，线程就被销毁了TERMINATED
         */
        Scanner scanner = new Scanner(System.in);
        Integer num = scanner.nextInt();
        if(num == 0){
            t.interrupt();
        }
    }
}
